package com.huisang.springboot.utils;


import cn.hutool.core.date.DateUtil;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;

import java.util.Date;

public class TokenUtil {

    public static <T> String getToken(String userId, String sign) {
        return JWT.create().withAudience(userId)   //以userID作为token载荷
                .withExpiresAt(DateUtil.offsetHour(new Date(), 2)) //2小时有效
                .sign(Algorithm.HMAC256(sign));     //以password作为token的密钥
    }
}
